<template>
	<el-menu default-active="1-4-1" class="el-menu-vertical-demo" @open="handleOpen" @close="handleClose"
		:collapse="isCollapse" background-color="#003c62" text-color="#fff" active-text-color="#00c4fc">
		<h2>题库管理系统</h2>
		<el-submenu :index="item.path.toString()" v-for="item in hasChildren" :key="item.path">
			<template slot="title">
				<i :class="'el-icon-'+item.icon"></i>
				<span slot="title">{{item.label}}</span>
			</template>
			<el-menu-item-group v-for="(subItem,subIndex) in item.children" :key="subItem.path">
				<el-menu-item :index="subIndex.toString()" :class="'el-icon-'+subItem.icon" @click="clickMenu(subItem)">{{subItem.label}}</el-menu-item>
			</el-menu-item-group>
		</el-submenu>
		<el-menu-item :index="item.path.toString()" v-for="item in noChildren" :key="item.path" @click="clickMenu(item)">
			<i :class="'el-icon-'+item.icon"></i>
			<span slot="title">{{item.label}}</span>
		</el-menu-item>
	</el-menu>
</template>

<script>
	export default {
		data() {
			return {
				isCollapse: false,
				menu: [{
						path: '/admin',
						name: 'admin',
						label: '教师管理',
						icon: 'user-solid',
						url: 'admin/admin',
						children: [{
								path: '/dataTotal',
								name: 'dataTotal',
								label: '数据统计',
								icon: 's-tools',
								url: 'admin/dataTotal',
							},
							{
								path: '/detail',
								name: 'detail',
								label: '试卷详情',
								icon: 'camera-solid',
								url: 'admin/detail',
							},
							{
								path: '/checkLog',
								name: 'checkLog',
								label: '查看日志',
								icon: 'menu',
								url: 'admin/checkLog',
							}
						]

					},
					{
						path: '/home',
						name: 'home',
						label: '学生管理',
						icon: 's-custom',
						url: 'home/home',
						children: [{
							path: '/account',
							name: 'account',
							label: '账号管理',
							icon: 's-tools',
							url: 'home/account',
						}]
					},
					{
						path: '/other',
						name: 'other',
						label: '其它',
						icon: 's-grid',
						url: 'other/other',
					},
				]
			};
		},
		methods: {
			handleOpen(key, keyPath) {
				console.log(key, keyPath);
			},
			handleClose(key, keyPath) {
				console.log(key, keyPath);
			},
			clickMenu(item) {
				this.$router.push({
					name: item.name
				})
			},
		},
		computed: {
			noChildren() {
				return this.menu.filter(item => !item.children)
			},
			hasChildren() {
				return this.menu.filter(item => item.children)
			}
		}
	}
</script>

<style scoped>
.el-menu-vertical-demo:not(.el-menu--collapse) {
    width: 200px;
    min-height: 400px;
  }
  .el-menu {
	  height: 100%;
	  border-right: 0;
  }
  h2 {
	  color: #fff;
	  text-align: center;
	  line-height: 54px;
  }
</style>
